package ch06_container.map;

import java.util.*;

public class TestMain {

    public static void main(String[] args) {
        Map<String, List<Test>> map = new HashMap<>();
        map.put("k2", List.of(new Test(2)));
        map.put("k3", List.of(new Test(3)));
        // map.put("k1", Arrays.asList(new Test(1)));
        map.put("k1", List.of(new Test(1)));

        LinkedHashMap<String, List<Test>> collect = map.entrySet()
                .stream()
                .sorted((e1, e2) -> {
                    Test t1 = e1.getValue().get(0);
                    Test t2 = e2.getValue().get(0);
                    return t1.getSortNo().compareTo(t2.getSortNo());
                })
                .collect(LinkedHashMap::new,
                        (map1, item) -> map1.put(item.getKey(), item.getValue()),
                        Map::putAll);

        System.out.println(collect);
    }
}
